package com.zxkj.commonpatrol.repoisity;

import com.allen.library.base.BaseHttpUtil;
import com.allen.library.interceptor.Transformer;
import com.allen.library.observer.CommonObserver;
import com.czy.basecommon.utils.base.BaseRepository;
import com.czy.basecommon.utils.constant.ItrackConstant;
import com.czy.basecommon.utils.tools.SPUtils;
import com.zxkj.commonpatrol.model.entity.HistoryQuestEntity;
import com.zxkj.commonpatrol.model.post.PostDevQuestPatrolHisoty;
import com.zxkj.commonpatrol.model.post.PostLogInfo;
import com.zxkj.commonpatrol.model.response.DevEvtQuestPatrolHistoryResponse;
import com.zxkj.commonpatrol.model.response.LogBean;
import com.zxkj.commonpatrol.net.ETFApiHelper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import okhttp3.ResponseBody;

public class QuestDetailRepoisity extends BaseRepository {
    public QuestDetailRepoisity() {

    }

    public void getData(MyBaseDataCallBack<List<HistoryQuestEntity>> listMyBaseDataCallBack){
        List<HistoryQuestEntity> historyQuestEntities=new ArrayList<>();
        for (int i = 0; i <4; i++) {
            HistoryQuestEntity historyQuestEntity=new HistoryQuestEntity();
            if (i%2==0){
                historyQuestEntity.setStatus(0);
            }else{
                historyQuestEntity.setStatus(1);
            }
            historyQuestEntity.setTitle("滅火器過期了"+i);
            historyQuestEntity.setTitle1("NiKO");
            historyQuestEntity.setTitle2("2020/09/01");
            historyQuestEntities.add(historyQuestEntity);
        }
        listMyBaseDataCallBack.onDataSuccessCallBack(historyQuestEntities);
    }


    public void getDevQuestPatrolHisoty(String RouteInspectNo, String PointNo, String DeviceNo, String QuestsNo, String QuestNo,int Type, MyBaseDataCallBack myBaseDataCallBack) {
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("LoginId", SPUtils.get(ItrackConstant.LOGINID, ""));
        map.put("Token", SPUtils.get(ItrackConstant.TOKEN, ""));
        map.put("Lang", 1);

        PostDevQuestPatrolHisoty postDevQuestPatrolHisoty = new PostDevQuestPatrolHisoty();
        postDevQuestPatrolHisoty.setDevEvtNo(DeviceNo);
        postDevQuestPatrolHisoty.setPointNo(PointNo);
        postDevQuestPatrolHisoty.setQuestNo(QuestNo);
        postDevQuestPatrolHisoty.setQuestsNo(QuestsNo);
        postDevQuestPatrolHisoty.setRouteInspectNo(RouteInspectNo);
        postDevQuestPatrolHisoty.setDevEvtType(Type);

        ETFApiHelper.geRadomApi().getDevQuestPatrolHisoty(map, new BaseHttpUtil<PostDevQuestPatrolHisoty>().convertVo2Json(postDevQuestPatrolHisoty))
                .compose(Transformer.switchSchedulers())
                .subscribe(new CommonObserver<DevEvtQuestPatrolHistoryResponse>() {
                    @Override
                    protected void onError(String errorMsg) {
                        myBaseDataCallBack.onDataFailCallBack(404, errorMsg);
                    }

                    @Override
                    protected void onSuccess(DevEvtQuestPatrolHistoryResponse devEvtQuestPatrolHistoryResponse) {
                        myBaseDataCallBack.onDataSuccessCallBack(devEvtQuestPatrolHistoryResponse);
                    }
                });
    }

    public void getFixException(String logId,MyBaseDataCallBack myBaseDataCallBack){
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("LoginId", SPUtils.get(ItrackConstant.LOGINID, ""));
        map.put("Token", SPUtils.get(ItrackConstant.TOKEN, ""));
        map.put("Lang", 1);

        ETFApiHelper.geRadomApi().getFixException(map,logId)
                .compose(Transformer.switchSchedulers())
                .subscribe(new CommonObserver<ResponseBody>() {
                    @Override
                    protected void onError(String errorMsg) {
                        myBaseDataCallBack.onDataFailCallBack(404,errorMsg);
                    }

                    @Override
                    protected void onSuccess(ResponseBody responseBody) {
                        myBaseDataCallBack.onDataSuccessCallBack(responseBody);
                    }
                });
    }
  /**
   *desc:
   *author:mid
   *addtime:2020/7/12 09:53
   */
    public void uploadLog(PostLogInfo postLogInfo, MyBaseDataCallBack myBaseDataCallBack){
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("LoginId", SPUtils.get(ItrackConstant.LOGINID, ""));
        map.put("Token", SPUtils.get(ItrackConstant.TOKEN, ""));
        map.put("Lang", 1);
        ETFApiHelper.geRadomApi().UploadLog(map,new BaseHttpUtil<PostLogInfo>().conVoMyJson(postLogInfo))
                .compose(Transformer.switchSchedulers())
                .subscribe(new CommonObserver<String>() {
                    @Override
                    protected void onError(String errorMsg) {
                        myBaseDataCallBack.onDataFailCallBack(404,errorMsg);
                    }

                    @Override
                    protected void onSuccess(String logId) {
                        myBaseDataCallBack.onDataSuccessCallBack(logId);
                    }
                });
    }
}
